//
//  FSCAboutUsController.swift
//  FamiliesSchoolConnection
//
//  Created by 花花蔡 on 2016/12/24.
//  Copyright © 2016年 com.HuaHuaCai. All rights reserved.
//

import UIKit

class FSCAboutUsController: UIViewController {

    let logoY = screenHeight * 0.182
    let cellStartY = screenHeight * 0.347
    let whiteViewHeight = screenHeight * 0.14
    let whiteViewSpace = screenHeight * 0.013

    let name = ["联系我们","枣尚智慧教育官网"]
    let nameValue = ["0769-26627823","http://www.zao-edu.com"]
    let name_1 = ["当前版本","开发人员"]
    let nameValue_1 = ["V6.0","CLL"]
    
    let navi = FSCLeftViewNavi()
    
    let CopyrightLabelY = screenHeight * 0.8
    let copyrightText = "东莞龙腾云教育科技有限公司  版权所有"
    let copyrightTextColor = UIColor.colorWithHex(hexColor: 0xd60a82)
    
    let english = "Copyright@2016-2020 Longteng cloud education"
    let english_2 = "ALL Rights Reserved"
    
//MARK:视图生命周期
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.layer.backgroundColor = UIColor.colorWithHex(hexColor: 0xf0f0f0).cgColor

        addNav()
        addLogo()
        
        addCell()
        addCopyrightLabel()
    }

    
    
//MARK:addNav
    func addNav() -> Void {
        
        navi.addNavigationInleftView(title: "关于我们", VC: self)
        navi.btnBlock = { [weak self] in
            self?.dismiss(animated: true, completion: nil)
        }

    }

//MARK:Logo
    func addLogo() -> Void {
        
        guard let iamge = UIImage(named: "logo") else {
            return
        }
        
        let logoX = screenWidth/2
        //图片层
        let topLayer = CALayer()
        topLayer.bounds = CGRect(x: 0.0, y: 0.0, width: iamge.size.width, height: iamge.size.height)
        topLayer.position = CGPoint(x: logoX, y: logoY)
        topLayer.contents = iamge.cgImage as Any
        view.layer.addSublayer(topLayer)
        
        //倒影层
        let reflectionLayer = CALayer()
        
        reflectionLayer.bounds = CGRect(x: 0.0, y: 0.5, width: iamge.size.width, height: iamge.size.height)
        
        reflectionLayer.position = CGPoint(x: logoX, y: logoY + iamge.size.height - 10)
        reflectionLayer.contents = topLayer.contents
        
        reflectionLayer.setValue(NSNumber.init(value: 180.0), forKeyPath: "transform.rotation.x")
        
        //遮罩层
        let graduentLayer = CAGradientLayer()
        
        graduentLayer.bounds = reflectionLayer.bounds
        graduentLayer.position = CGPoint(x: reflectionLayer.bounds.size.width/2, y: reflectionLayer.bounds.size.height/2)
        graduentLayer.colors = Array(arrayLiteral: UIColor.clear.cgColor,UIColor.black.cgColor)
        //y：改变遮罩的程度，即透明度
        graduentLayer.startPoint = CGPoint(x: 0.3, y: 0.0)
        graduentLayer.endPoint = CGPoint(x: 0.3, y: 2.0)
        reflectionLayer.mask = graduentLayer
        
        view.layer.addSublayer(reflectionLayer)
    }

    
//MARK:cell
    func addCell() -> Void {
        let leftSpeace = 20.0
        
        for item in 0..<2 {
            var whiteHeight = whiteViewHeight * CGFloat(item)
            if item == 1 {
                whiteHeight += whiteViewSpace
            }
            let whiteView = UIView(frame: CGRect(x: 0, y: cellStartY + whiteHeight, width: screenWidth, height: whiteViewHeight))
            whiteView.backgroundColor = UIColor.white
            view.addSubview(whiteView)
            
            
            let line = UIView(frame: CGRect(x: CGFloat(leftSpeace), y: whiteView.bounds.height/2, width: screenWidth - CGFloat(2.0 * leftSpeace) , height: 1.0))
            line.backgroundColor = UIColor.colorWithHex(hexColor: 0xb2b2b2)
            
            whiteView.addSubview(line)
            
            
            
            if item == 0 {
                
                for item in 0..<2 {
                   
                    let width:CGFloat = whiteView.bounds.width/2
                    let height:CGFloat = whiteView.bounds.height/2
                    
                   whiteView.addSubview(addLabelWithArrayAndWH(arr: name_1, width: width, height: height, item: item))
                    
                    let visionNumL = UILabel(frame: CGRect(x: screenWidth - width - 8, y:height * CGFloat(item), width: width, height: height))
                    visionNumL.text = nameValue_1[item]
                    visionNumL.textAlignment = .right
                    visionNumL.textColor = UIColor.colorWithHex(hexColor: 0xb2b2b2)
                    whiteView.addSubview(visionNumL)
                }
            }
            
            if item == 1 {
                
                for item in 0..<2 {
                    //label
                    let width:CGFloat = whiteView.bounds.width/2
                    let height:CGFloat = whiteView.bounds.height/2
                    
                    whiteView.addSubview(addLabelWithArrayAndWH(arr: name, width: width, height: height, item: item))
                    
                    //按钮
                    let btn = UIButton(frame: CGRect(x: screenWidth - width - 8, y:height * CGFloat(item), width: width, height: height))
                    btn.setTitle(nameValue[item], for: .normal)
                    btn.setTitleColor(UIColor.colorWithHex(hexColor: 0xd60a82), for: .normal)
                    btn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
                    btn.contentHorizontalAlignment = .right
                    btn.tag = btnBaseTAG + item
                    btn.addTarget(self, action: #selector(btnClicked(btn:)), for: .touchUpInside)
                    whiteView.addSubview(btn)
                }
            }
            
        }
        
        for item in 0..<4 {
           
            var viewHeight = whiteViewHeight * CGFloat(item)
            
            if item == 2 {
                viewHeight += whiteViewSpace - whiteViewHeight
            }
            if item == 3 {
                viewHeight = whiteViewHeight * CGFloat(item) - whiteViewHeight + whiteViewSpace
            }
            
            let viewLine = UIView(frame: CGRect(x: 0, y: cellStartY + viewHeight, width: screenWidth, height: 1))
            viewLine.backgroundColor = UIColor.lightGray
            view.addSubview(viewLine)
            
        }

        
}

    
//MARK:加载版权文字
    func addCopyrightLabel() -> Void {
        
        let label  = UILabel(frame: CGRect(x: 0, y: CopyrightLabelY, width: screenWidth, height: 17))
        label.text = copyrightText
        label.textColor = copyrightTextColor
        label.textAlignment = .center
        label.font = UIFont.systemFont(ofSize: 15)
        view.addSubview(label)
        
        let englishY = label.frame.maxY + 20
        let englishL = UILabel(frame: CGRect(x: 0, y: englishY, width: screenWidth, height: 13))
        englishL.text = english
        englishL.textColor = UIColor.colorWithHex(hexColor: 0x666666)
        englishL.font = UIFont.boldSystemFont(ofSize: 11)
        englishL.textAlignment = .center
        view.addSubview(englishL)
        
        let english_1Y = englishL.frame.maxY + 10
        let english_1L = UILabel(frame: CGRect(x: 0, y: english_1Y, width: screenWidth, height: 13))
        english_1L.text = english_2
        english_1L.textAlignment = .center
        english_1L.textColor = UIColor.colorWithHex(hexColor: 0x666666)
        english_1L.font = UIFont.boldSystemFont(ofSize: 11)
        view.addSubview(english_1L)
        
    }

    
    func addLabelWithArrayAndWH(arr:Array<String>,width:CGFloat,height:CGFloat,item:Int) -> UILabel {
        
        let visionLabel = UILabel(frame: CGRect(x: 8, y: CGFloat(height * CGFloat(item)), width: width, height: height))
        visionLabel.text = arr[item]
        visionLabel.textAlignment = .left
        visionLabel.textColor = UIColor.colorWithHex(hexColor: 0x4c4c4c)
        
        return visionLabel
    }
    
    
//MARK:btn点击事件
    func btnClicked(btn:UIButton) -> Void {
        switch btn.tag - btnBaseTAG {
        case 0:
            //打电话
            print("打电话")
        case 50:
            dismiss(animated: true, completion: nil)
        default:
            //打开网页
            print("打开网页")
        }
    }


  }
